package cn.com.cfae.iras.doc.analyze.components.iaad;

import cn.com.cfae.iras.doc.analyze.beans.iaad.IaadIndicatorGradeDetail;
import cn.com.cfae.iras.doc.analyze.beans.iaad.IndustryIndicatorList;
import cn.com.cfae.iras.doc.analyze.beans.iaad.IndustryIndicatorThreshold;
import cn.com.cfae.iras.doc.analyze.beans.web.ContentAndPosition;
import cn.com.cfae.iras.doc.analyze.components.BaseComponent;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.components.common.UnitEnum;
import cn.com.cfae.iras.doc.analyze.components.integrity.I1001;
import cn.com.cfae.iras.doc.analyze.config.ApplicationContextHelper;
import cn.com.cfae.iras.doc.analyze.parse.kv.KVText;
import cn.com.cfae.iras.doc.analyze.parse.model.DocumentModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractBizModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractItem;
import com.google.gson.GsonBuilder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 佟媛媛 on 18/11/7.
 * 房地产
 */

@Component("FDC02")
@Scope("prototype")
public class FDC02  extends BaseComponent {

    private static Logger log = LoggerFactory.getLogger(FDC02.class);

    public List<IaadIndicatorGradeDetail> handlerIAAD(){
        List<IaadIndicatorGradeDetail> list = new ArrayList<>();
        List<IaadIndicatorGradeDetail> XSJE = getXSJE();//市场地位：近一年销售金额
        if(CollectionUtils.isNotEmpty(XSJE)) list.addAll(XSJE);
        IaadIndicatorGradeDetail CH_YSZK = getCH_YSZK();//库存压力和项目运营能力
        if(CH_YSZK!=null) list.add(CH_YSZK);
        List<IaadIndicatorGradeDetail> DSMJZB = getDSMJZB();//项目分散性：一二线城市待售面积占比
        if(CollectionUtils.isNotEmpty(DSMJZB)) list.addAll(DSMJZB);
        List<IaadIndicatorGradeDetail> GHJZMJ_QYXSMJ = getGHJZMJ_QYXSMJ();//土地储备
        if(CollectionUtils.isNotEmpty(GHJZMJ_QYXSMJ)) list.addAll(GHJZMJ_QYXSMJ);
        IaadIndicatorGradeDetail SJYJ = getSJYJ();//是否出具非标准审计意见
        if(SJYJ!=null) list.add(SJYJ);
        IaadIndicatorGradeDetail MLL = getMLL();//盈利能力：毛利率
        if(MLL!=null) list.add(MLL);
        IaadIndicatorGradeDetail XJL = getXJL();//盈利质量：经营性净现金流
        if(XJL!=null) list.add(XJL);
        IaadIndicatorGradeDetail ZFZ_YSZK = getZFZ_YSZK();//杠杆风险：调整预收账款后资产负债率
        if(ZFZ_YSZK!=null) list.add(ZFZ_YSZK);
        IaadIndicatorGradeDetail LDFZ_YSZK = getLDFZ_YSZK();//短期偿债能力
        if(LDFZ_YSZK!=null) list.add(LDFZ_YSZK);
        IaadIndicatorGradeDetail ZFZ = getZFZ();//长期偿债能力
        if(ZFZ!=null) list.add(ZFZ);
        IaadIndicatorGradeDetail ZYYWSR_PJCH = getZYYWSR_PJCH();//项目运营能力（去化速度）
        if(ZYYWSR_PJCH!=null) list.add(ZYYWSR_PJCH);
        log.info("房地产指标：{}",new GsonBuilder().create().toJson(list));
        return list;
    }

    //市场地位：近一年销售金额
    /**
     1、市场地位：近一年销售金额 --》XSJE
     单位：亿元
     --》
     */
    private List<IaadIndicatorGradeDetail> getXSJE(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("SCDW");
            List<IaadIndicatorGradeDetail> list = new ArrayList<>();
            int pageNum = getChapterModel("M-5").getStartPage();
            List<KVText> kvTextList = getKVTextValues("M-5","FDC","XSJE");
            if(CollectionUtils.isNotEmpty(kvTextList)){
                for(KVText kvText : kvTextList){
                    String value = kvText.getText();
                    double v = getDouble(value);
                    List<ContentAndPosition> textPositionList = getContentAndPositionList2(kvText);
                    if(StringUtils.isEmpty(value)){
                        continue;
                    }
                    IaadIndicatorGradeDetail iaadIndicatorGradeDetail = getIaadIndicatorGradeDetail(indicator,textPositionList,doubleToBigDecimal(v),pageNum,value,String.format("近一年销售金额%s",value));
                    if(iaadIndicatorGradeDetail!=null) list.add(iaadIndicatorGradeDetail);
                }
            }
            return list;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //库存压力和项目运营能力
    /**
     2、库存压力和项目运营能力 --》存货/预收账款 --》CH/YSZK
     --》M-6、ZCFZ.CH、ZCFZ.YSKX
     "1、近一年年报
     2、存货/预收账款"
     */
    private IaadIndicatorGradeDetail getCH_YSZK(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("KCYL-XMYYNL");
            String CHS =null,YSKXS = null;
            double CH =0,YSKX = 0,v1=0;
            int pageNum = getChapterModel("M-6").getStartPage();
            ExtractBizModel model = getModel("M-6","ZCFZ");
            Map<String, ExtractItem> col1 = model.getTable(getJYN(model.getTables()));
            if(MapUtils.isNotEmpty(col1)){
                if(col1.get("CH")!=null && col1.get("CH").getValue()!=null){
                    CHS = col1.get("CH").getValue().getText();
                    CH = getDouble(CHS);
                }
                if(col1.get("YSKX")!=null && col1.get("YSKX").getValue()!=null){
                    YSKXS = col1.get("YSKX").getValue().getText();
                    YSKX = getDouble(YSKXS);
                }
                if(CH!=0 && YSKX!=0){
                    v1 = getTwoDecimal(CH/YSKX);
                }
            }
            if(StringUtils.isEmpty(CHS) && StringUtils.isEmpty(YSKXS)){
                return null;
            }
            CHS=CHS+model.getUnitType();
            YSKXS=YSKXS+model.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v1),"",pageNum,String.format("近一年存货%s，近一年预收账款%s",CHS,YSKXS));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //项目分散性：一二线城市待售面积占比
    /**
     3、项目分散性：一二线城市待售面积占比 --》DSMJZB
     "1、需要人工标记同义词；
     2、抽取不到人工输入；"
     单位：%
     */
    private List<IaadIndicatorGradeDetail> getDSMJZB(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("XMFSX");
            List<IaadIndicatorGradeDetail> list = new ArrayList<>();
            List<KVText> kvTextList = getKVTextValues("M-5","FDC","DSMJZB");
            int pageNum = getChapterModel("M-5").getStartPage();
            if(CollectionUtils.isNotEmpty(kvTextList)){
                for(KVText kvText : kvTextList){
                    String value = kvText.getText();
                    double v = getDouble(value);
                    List<ContentAndPosition> textPositionList = getContentAndPositionList2(kvText);
                    if(StringUtils.isEmpty(value)){
                        continue;
                    }
                    IaadIndicatorGradeDetail iaadIndicatorGradeDetail = getIaadIndicatorGradeDetail(indicator,textPositionList,doubleToBigDecimal(v),"",pageNum,String.format("一二线城市待售面积占比%s",value));
                    if(iaadIndicatorGradeDetail!=null) list.add(iaadIndicatorGradeDetail);
                }
            }
            return list;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //土地储备 --》土地储备规划建筑面积 /当年签约销售面积
    /**
     * todo 只取了第一个值
     4、土地储备 --》土地储备规划建筑面积 /当年签约销售面积 --》GHJZMJ/QYXSMJ
     "1、表格分别列示，最后有总计面积；
     2、近一年销售面积；
     3、占比=土地储备规划建筑面积 /当年签约销售面积"
     */
    private List<IaadIndicatorGradeDetail> getGHJZMJ_QYXSMJ(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("TDCB");
            List<IaadIndicatorGradeDetail> list = new ArrayList<>();
            List<KVText> GHJZMJ = getKVTextValues("M-5","FDC","GHJZMJ");
            List<KVText> QYXSMJ = getKVTextValues("M-5","FDC","QYXSMJ");
            String GHJZMJS=null,QYXSMJS = null;
            double GHJZMJv=0,QYXSMJv=0,v=0;
            int pageNum = getChapterModel("M-5").getStartPage();
            if(CollectionUtils.isNotEmpty(GHJZMJ)){
                GHJZMJS = GHJZMJ.get(0).getText();
                GHJZMJv = getDouble(GHJZMJS);
            }
            if(CollectionUtils.isNotEmpty(QYXSMJ)){
                QYXSMJS = QYXSMJ.get(0).getText();
                QYXSMJv = getDouble(QYXSMJS);
            }
            if(GHJZMJv!=0 && QYXSMJv!=0){
                v = getTwoDecimal(GHJZMJv/QYXSMJv);
                IaadIndicatorGradeDetail iaadIndicatorGradeDetail = getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v),"",pageNum,String.format("土地储备规划建筑面积%s，当年签约销售面积%s",GHJZMJS,QYXSMJS));
                if(iaadIndicatorGradeDetail!=null) list.add(iaadIndicatorGradeDetail);
            }
            return list;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //是否出具非标准审计意见
    /**
     5、是否出具非标准审计意见 --》SJYJ
     --》M-6、关键字
     1、关键词检查
     */
    private IaadIndicatorGradeDetail getSJYJ(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("SFCJFBZSJYJ");
            Map<String,String> keywords = new HashMap<>();
            keywords.put("标准无保留","5");
            keywords.put("带强调段的无保留","20");
            keywords.put("保留意见","100");
            Class clazz = Class.forName("cn.com.cfae.iras.doc.analyze.components.integrity.I1001");
            I1001 i1001 = (I1001) ApplicationContextHelper.getBean("I1001");
            Method setExtractData = clazz.getMethod("setExtractData", DocumentModel.class);
            setExtractData.invoke(i1001, getExtractData());
            Method ifKeywordExist2 = clazz.getMethod("ifKeywordExist2", String.class);
            IaadIndicatorGradeDetail detail = sjyj(i1001,"带强调段的无保留",ifKeywordExist2,keywords,indicator,"20");
            if(detail!=null){
                return detail;
            }else{
                IaadIndicatorGradeDetail detail1 = sjyj(i1001,"标准无保留",ifKeywordExist2,keywords,indicator,"5");
                if(detail1!=null){
                    return detail1;
                }else{
                    return sjyj(i1001,"保留意见",ifKeywordExist2,keywords,indicator,"100");
                }
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    private IaadIndicatorGradeDetail sjyj(I1001 i1001,String key,Method ifKeywordExist2,Map<String,String> keywords,IndustryIndicatorList indicator,String thresholdScore) throws Exception{
        i1001.setKeyword(key);
        Map map = (Map)ifKeywordExist2.invoke(i1001, "M-6");
        if(MapUtils.isNotEmpty(map)){
            boolean boo = (boolean)map.get("exist");
            if(boo){
                double score = Double.valueOf(keywords.get(key))*Double.valueOf(indicator.getWeight());
                return getIaadIndicatorGradeDetail(indicator,key, getTwoDecimal(score)+"", key,thresholdScore, (int)map.get("pageNum"), key);
            }
        }
        return null;
    }

    //盈利能力：毛利率
    /**
     6、盈利能力：毛利率 --》MLL --》（营业收入-营业成本）/营业收入 --》(YYSR-YYCB)/YYSR --》(目前采用抽取值，不适用公式计算)
     --》M-5、MLL.MLL 或 LR.YYSR、LR.YYCB
     1、近一年，M-5章节获取；
     单位：%
     */
    private IaadIndicatorGradeDetail getMLL(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("YLNL");
    //        直接抽取
            String MLLS = null;
            double MLLD = 0;
            boolean boo = false;
            int pageNum = getChapterModel("M-5").getStartPage();
            ExtractBizModel model = getModel("M-5","MLL");
            List<Map<String, ExtractItem>> mll = model.getTable2(getJYN(model.getTables2()));
            String[] arr = new String[]{"房地产","房产"};
            for(int i=0;i<arr.length;i++){
                if(mll==null) break;
                if(boo) break;
                for(Map<String, ExtractItem> item : mll){
                    if(boo) break;
                    if(item.get("YWBK")!=null && item.get("YWBK").getValue()!=null){
                        if(StringUtils.isNotEmpty(item.get("YWBK").getValue().getText()) && item.get("YWBK").getValue().getText().contains(arr[i])){
                            if(item.get("ZB")!=null && item.get("ZB").getValue()!=null){
                                MLLS = item.get("ZB").getValue().getText();
                                MLLD = getDouble(MLLS);
                                pageNum = item.get("ZB").getValue().getPageNumber();
                            }
                            boo = true;
                        }
                    }
                }
            }
            if(StringUtils.isEmpty(MLLS)){
                return null;
            }
            if(!MLLS.contains("%")) MLLS=MLLS+"%";
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(MLLD),"",pageNum,String.format("毛利率%s",MLLS));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
//        使用公式计算（营业收入-营业成本）/营业收入
//        Map<String, ExtractItem> JLRcol = getModel("M-6","LR").getTable(getSNJYQ()[2]);
//        String YYSRS = null,YYCBS = null;
//        double YYSR = 0,YYCB = 0,v = 0;
//        if(MapUtils.isNotEmpty(JLRcol) && JLRcol.get("YYSR")!=null && JLRcol.get("YYSR").getValue()!=null){
//            YYSRS = JLRcol.get("YYSR").getValue().getText();
//            YYSR = getDouble(YYSRS);
//        }
//        if(MapUtils.isNotEmpty(JLRcol) && JLRcol.get("YYCB")!=null && JLRcol.get("YYCB").getValue()!=null){
//            YYCBS = JLRcol.get("YYCB").getValue().getText();
//            YYCB = getDouble(YYCBS);
//        }
//        if(YYSR!=0){
//            v = ((YYSR-YYCB)/YYSR);
//        }
//        if(StringUtils.isEmpty(YYSRS) && StringUtils.isEmpty(YYCBS)){
//            return null;
//        }
//        return getIaadIndicatorGradeDetail(indicator,v+"",0,String.format("近一年营业收入%s,近一年营业成本%s",YYSR,YYCB));
    }

    //盈利质量：经营性净现金流
    /**
     7、盈利质量：经营性净现金流 --》XJL
     --》M-6、XJLL.JYHDCSXJLLJE
     "1、近2年及一期财务数据；
     2、M-6获取财务报表章节获取；"
     */
    private IaadIndicatorGradeDetail getXJL(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("YLZL");
            String thresholdValue=null,automateScore=null,thresholdScore=null;
            double v1=0,v2=0,v3=0;
            String s1=null,s2=null,s3=null;
            int pageNum = getChapterModel("M-6").getStartPage();
            ExtractBizModel model = getModel("M-6","XJLL");
            String[] years = getSNJYQ(model.getTables());
            if(years!=null && years.length>=3){
                Map<String, ExtractItem> col1 = model.getTable(years[1]);
                Map<String, ExtractItem> col2 = model.getTable(years[2]);
                Map<String, ExtractItem> col3 = model.getTable(years[0]);
                if(col1!=null && col2!=null && col3!=null){
                    KVText value1 = col1.get("JYHDCSXJLLJE")!=null?col1.get("JYHDCSXJLLJE").getValue():null;
                    KVText value2 = col2.get("JYHDCSXJLLJE")!=null?col2.get("JYHDCSXJLLJE").getValue():null;
                    KVText value3 = col3.get("JYHDCSXJLLJE")!=null?col3.get("JYHDCSXJLLJE").getValue():null;
                    if(value1!=null && value2!=null && value3!=null){
                        s1 = value1.getText();
                        v1 = getDouble(s1);
                        s2 = value2.getText();
                        v2 = getDouble(s2);
                        s3 = value3.getText();
                        v3 = getDouble(s3);
                        Map map = getXJLScoreAndThresholdValue(v1,v2,v3,indicator.getWeight(),indicator.getThresholdList());
                        thresholdValue = (String) map.get("thresholdValue");
                        automateScore = (String) map.get("automateScore");
                        thresholdScore = (String) map.get("thresholdScore");
                    }
                }
            }
            if(StringUtils.isEmpty(s1) && StringUtils.isEmpty(s2) && StringUtils.isEmpty(s3)){
                return null;
            }
            s1=s1+model.getUnitType();
            s2=s2+model.getUnitType();
            s3=s3+model.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v1)+";"+doubleToBigDecimal(v2)+";"+doubleToBigDecimal(v3),automateScore,thresholdValue,thresholdScore,pageNum,String.format("近两年及一期经营性现金流%s,%s,%s",s1,s2,s3));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //    经营性现金流量净额分数及阈值计算
    private Map getXJLScoreAndThresholdValue(double v1,double v2,double v3,String weight,List<IndustryIndicatorThreshold> industryIndicatorThresholdList){
        Map rs = new HashMap();
        double automateScore = 0;//得分 = 阈值对应分数 * 权重
        int score = 0,thresholdScore=0;
        String thresholdValue = null;
        if(v1>0 && v2>0 && v3>0){
            thresholdScore=score = 5;
            thresholdValue = "均为正";
        }else if(v3<0){
            thresholdScore=score = 10;
            thresholdValue = "近一期为负";
        }else if(v2<0 && v3<0){
            thresholdScore=score = 20;
            thresholdValue = "近一年一期为负";
        }else if((v1<0 && v2<0) || (v2<0 && v3<0)){
            thresholdScore=score = 50;
            thresholdValue = "连续两年为负";
        }else{
            thresholdScore=score = 100;
            thresholdValue = "其他";
        }
        automateScore = score*Double.valueOf(weight);
        rs.put("automateScore",automateScore+"");
        rs.put("thresholdValue",thresholdValue);
        rs.put("thresholdScore",thresholdScore==0?null:thresholdScore+"");
        return rs;
    }

    //杠杆风险：调整预收账款后资产负债率
    /**
     8、杠杆风险：调整预收账款后资产负债率 --》（负债-预收账款）/（资产-预收账款）--》(ZFZ-YSZK)/(ZZC-YSZK)
     --》M-6、ZCFZ.FZHJ、ZCFZ.YSKX、ZCFZ.ZCZJ、ZCFZ.YSKX
     "1、近一年年报；
     2、负债-预收账款/资产-预收账款；"
     单位：%
     */
    private IaadIndicatorGradeDetail getZFZ_YSZK(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("GGFX");
            ExtractBizModel model = getModel("M-6","ZCFZ");
            Map<String, ExtractItem> col = model.getTable(getJYN(model.getTables()));
            String FZHJS = null,YSKXS = null,ZCZJS = null;
            double FZHJ = 0,YSKX = 0,ZCZJ = 0,d = 0;
            int pageNum = getChapterModel("M-6").getStartPage();
            if(MapUtils.isNotEmpty(col) && col.get("FZHJ")!=null && col.get("FZHJ").getValue()!=null){
                FZHJS = col.get("FZHJ").getValue().getText();
                FZHJ = getDouble(FZHJS);
            }
            if(MapUtils.isNotEmpty(col) && col.get("YSKX")!=null && col.get("YSKX").getValue()!=null){
                YSKXS = col.get("YSKX").getValue().getText();
                YSKX = getDouble(YSKXS);
            }
            if(MapUtils.isNotEmpty(col) && col.get("ZCZJ")!=null && col.get("ZCZJ").getValue()!=null){
                ZCZJS = col.get("ZCZJ").getValue().getText();
                ZCZJ = getDouble(ZCZJS);
            }
            if(ZCZJ-YSKX!=0){
                d =getTwoDecimal((FZHJ-YSKX)/(ZCZJ-YSKX));
            }
            if(StringUtils.isEmpty(FZHJS) && StringUtils.isEmpty(YSKXS) && StringUtils.isEmpty(ZCZJS)){
                return null;
            }
            FZHJS = FZHJS+model.getUnitType();
            YSKXS = YSKXS+model.getUnitType();
            ZCZJS = ZCZJS+model.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(d),"%",pageNum,String.format("负债：%s，资产：%s，预收账款：%s",FZHJS,ZCZJS,YSKXS));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //短期偿债能力
    /**
     9、短期偿债能力 --》经营性现金流入/短期债务（流动负债-预收账款） --》XJL/(LDFZ-YSZK)
     --》M-6、XJLL.JYHDCSXJLLJE、ZCFZ.LDFZHJ、ZCFZ.YSKX
     "1、近一年年报；
     2、经营性现金流入/短期债务（流动负债-预收账款）；"
     */
    private IaadIndicatorGradeDetail getLDFZ_YSZK(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("DQCZNL");
            String LDFZHJS = null,YSKXS = null,JYHDCSXJLLS = null;
            double LDFZHJ = 0,YSKX = 0,JYHDCSXJLL = 0,v = 0;
            int pageNum = getChapterModel("M-6").getStartPage();
            ExtractBizModel ZCFZmodel = getModel("M-6","ZCFZ");
            ExtractBizModel XJLLmodel = getModel("M-6","XJLL");
            Map<String, ExtractItem> ZCFZcol = ZCFZmodel.getTable(getJYN(ZCFZmodel.getTables()));
            Map<String, ExtractItem> XJLLcol = XJLLmodel.getTable(getJYN(XJLLmodel.getTables()));
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("LDFZHJ")!=null && ZCFZcol.get("LDFZHJ").getValue()!=null){
                LDFZHJS = ZCFZcol.get("LDFZHJ").getValue().getText();
                LDFZHJ = getDouble(LDFZHJS);
            }
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("YSKX")!=null && ZCFZcol.get("YSKX").getValue()!=null){
                YSKXS = ZCFZcol.get("YSKX").getValue().getText();
                YSKX = getDouble(YSKXS);
            }
            if(MapUtils.isNotEmpty(XJLLcol) && XJLLcol.get("JYHDCSXJLLJE")!=null && XJLLcol.get("JYHDCSXJLLJE").getValue()!=null){
                JYHDCSXJLLS = XJLLcol.get("JYHDCSXJLLJE").getValue().getText();
                JYHDCSXJLL = getDouble(JYHDCSXJLLS);
            }
            if(YSKX-LDFZHJ!=0){
                v = getTwoDecimal(JYHDCSXJLL/(LDFZHJ-YSKX));
            }
            if(StringUtils.isEmpty(LDFZHJS) && StringUtils.isEmpty(YSKXS) && StringUtils.isEmpty(JYHDCSXJLLS)){
                return null;
            }
            JYHDCSXJLLS=JYHDCSXJLLS+XJLLmodel.getUnitType();
            LDFZHJS=LDFZHJS+ZCFZmodel.getUnitType();
            YSKXS=YSKXS+ZCFZmodel.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v),"",pageNum,String.format("经营性现金流入：%s，流动负债：%s，预收账款：%s",JYHDCSXJLLS,LDFZHJS,YSKXS));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //长期偿债能力
    /**
     10、长期偿债能力 --》现金类资产（货币资金、可供出售金融资产、应收票据）+存货+投资性房地产-预收款项/全部债务（总负债）（剔除预收账款） --》(YSPJ+CH+TZXFDC-YSZK)/ZFZ
     --》M-6、ZCFZ.HBZJ、ZCFZ.CH、ZCFZ.FZHJ、ZCFZ.YSKX
     "1、近一年年报；
     2、现金类资产（货币资金、可供出售金融资产、应收票据）+存货+投资性房地产-预收款项/全部债务（总负债）（剔除预收账款）"
     */
    private IaadIndicatorGradeDetail getZFZ(){
        try{
            IndustryIndicatorList indicator = getIndustryIndicatorList("CQCZNL");
            String HBZJS=null,CHS=null,FZHJS=null,YSKXS=null,TZXFDCS=null;
            double HBZJ=0,CH=0,FZHJ=0,YSKX=0,TZXFDC=0,v=0;
            int pageNum = getChapterModel("M-6").getStartPage();
            ExtractBizModel model =  getModel("M-6","ZCFZ");
            Map<String, ExtractItem> ZCFZcol =model.getTable(getJYN(model.getTables()));
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("HBZJ")!=null && ZCFZcol.get("HBZJ").getValue()!=null){
                HBZJS = ZCFZcol.get("HBZJ").getValue().getText();
                HBZJ = getDouble(HBZJS);
            }
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("CH")!=null && ZCFZcol.get("CH").getValue()!=null){
                CHS = ZCFZcol.get("CH").getValue().getText();
                CH = getDouble(CHS);
            }
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("FZHJ")!=null && ZCFZcol.get("FZHJ").getValue()!=null){
                FZHJS = ZCFZcol.get("FZHJ").getValue().getText();
                FZHJ = getDouble(FZHJS);
            }
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("YSKX")!=null && ZCFZcol.get("YSKX").getValue()!=null){
                YSKXS = ZCFZcol.get("YSKX").getValue().getText();
                YSKX = getDouble(YSKXS);
            }
            if(MapUtils.isNotEmpty(ZCFZcol) && ZCFZcol.get("TZXFDC")!=null && ZCFZcol.get("TZXFDC").getValue()!=null){
                TZXFDCS = ZCFZcol.get("TZXFDC").getValue().getText();
                TZXFDC = getDouble(TZXFDCS);
            }
            if(FZHJ-YSKX!=0){
                v = getTwoDecimal((HBZJ+CH+TZXFDC-YSKX)/(FZHJ-YSKX));
            }
            if(StringUtils.isEmpty(HBZJS) && StringUtils.isEmpty(CHS) && StringUtils.isEmpty(FZHJS) && StringUtils.isEmpty(YSKXS) && StringUtils.isEmpty(TZXFDCS)){
                return null;
            }
            HBZJS=HBZJS+model.getUnitType();
            CHS=CHS+model.getUnitType();
            YSKXS=YSKXS+model.getUnitType();
            FZHJS=FZHJS+model.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v),"",pageNum,String.format("货币资金：%s，存货：%s，预收款项：%s，总负债：%s",HBZJS,CHS,YSKXS,FZHJS));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    //项目运营能力（去化速度）
    /**
     11、项目运营能力（去化速度）--》近一年主营业务收入/平均存货） --》ZYYWSR/PJCH
     --》M-6、LR.YYSR、ZCFZ.CH
     "1、近一年年报
     2、营业收入是近一年
     3、存货是近2年平均值，16、17年年报；"
     */
    private IaadIndicatorGradeDetail getZYYWSR_PJCH(){
        try{
            String YYSRS=null,CHS1=null,CHS2=null;
            double YYSR=0,CH1=0,CH2=0,v=0;
            int pageNum = getChapterModel("M-6").getStartPage();
            IndustryIndicatorList indicator = getIndustryIndicatorList("XMYYNL");
            ExtractBizModel model = getModel("M-6","LR");
            Map<String, ExtractItem> JLRcol1 = model.getTable(getJYN(model.getTables()));
            if(MapUtils.isNotEmpty(JLRcol1) && JLRcol1.get("YYSR")!=null && JLRcol1.get("YYSR").getValue()!=null){
                YYSRS = JLRcol1.get("YYSR").getValue().getText();
                YYSR = getDouble(YYSRS);
            }
            ExtractBizModel model1 = getModel("M-6","ZCFZ");
            String[] years = getSNJYQ(model1.getTables());
            if(years!=null && years.length>=3){
                Map<String, ExtractItem> ZCFZcol1 = model1.getTable(years[1]);
                Map<String, ExtractItem> ZCFZcol2 = model1.getTable(years[2]);
                if(MapUtils.isNotEmpty(ZCFZcol1) && ZCFZcol1.get("CH")!=null && ZCFZcol1.get("CH").getValue()!=null){
                    CHS1 = ZCFZcol1.get("CH").getValue().getText();
                    CH1 = getDouble(CHS1);
                }
                if(MapUtils.isNotEmpty(ZCFZcol2) && ZCFZcol2.get("CH")!=null && ZCFZcol2.get("CH").getValue()!=null){
                    CHS2 = ZCFZcol2.get("CH").getValue().getText();
                    CH2 = getDouble(CHS2);
                }
            }
            if(YYSR!=0 && CH1!=0 && CH2!=0){
                v = getTwoDecimal(YYSR/((CH1+CH2)/2));
            }
            if(StringUtils.isEmpty(YYSRS) && StringUtils.isEmpty(CHS1) && StringUtils.isEmpty(CHS2)){
                return null;
            }
            YYSRS=YYSRS+model.getUnitType();
            CHS1=CHS1+model1.getUnitType();
            CHS2=CHS2+model1.getUnitType();
            return getIaadIndicatorGradeDetail(indicator,doubleToBigDecimal(v),"",pageNum,String.format("近一年营业收入：%s，近两年存货：%s，%s",YYSRS,CHS1,CHS2));
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    @Override
    public List<ComponentResult> handlerM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerBM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerDM() {
        return null;
    }

    @Override
    public List<ComponentResult> handlerBDM() {
        return null;
    }
}
